const db = require("../../lib/db");

//获取私信
exports.getMessagePage = (pageSize, nowPage) => {
    let _sql = `SELECT * FROM message order by id desc limit ?, ?`;
    let params = [(nowPage - 1) * pageSize, pageSize];
    return db.queryWithPool(_sql, params);
  };
  
  //获取私信总数
  exports.getMessageCount = () => {
    let _sql = `SELECT count(*) AS count FROM message`;
    return db.queryWithPool(_sql);
  };

//获取未读私信总数
exports.getUnreadMessageCount = () => {
    let _sql = `SELECT count(*) AS count FROM message where isread = 0`;
    return db.queryWithPool(_sql);
  };

  //私信状态更新
  exports.updateMessageStatus = (id) => {
    let _sql = `UPDATE message SET isread = 1 WHERE id = ?`;
    return db.queryWithPool(_sql, [id]);
  };
  
  //删除私信
  exports.deleteMessage = (id) => {
    let _sql = `DELETE FROM message WHERE id = ?`;
    return db.queryWithPool(_sql, [id]);
  };